#-*- coding: UTF-8 -*-
__author__ = 'Jinkey'
import scipy as sp
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
import random
data = sp.genfromtxt('../Building Machine Learning Systems with Python/1400OS_01_Codes/data/web_traffic.tsv',delimiter='\t')
x = data[:,0]
y = data[:,1]
x = x[~sp.isnan(y)]
y = y[~sp.isnan(y)]
i = 0

#三点随机颜色
colors = []
while i<15:
    r = random.uniform(0.01, 0.99)
    g = random.uniform(0.01, 0.99)
    b = random.uniform(0.01, 0.99)
    color = (r,g,b,0.6)
    colors.append(color)
    i += 1
plt.scatter(x, y, c=colors, linewidths=0)

fp1 = sp.polyfit(x, y, 1)
f1 = sp.poly1d(fp1)
f1x = sp.linspace(0,x[-1],1000)
plt.plot(f1x,f1(f1x),linewidth=3.5,c=(0.2,0.6,0.9,0.8))

fp2 = sp.polyfit(x,y,2)
f2 = sp.poly1d(fp2)
f2x = sp.linspace(0,x[-1],1000)
plt.plot(f2x,f2(f2x),linewidth=3.5,c=(0.5,0.3,0.9,0.8))

plt.show()